package com.icinfo.cloud.provider.punish.common.publicsecurityentrust.service.impl;


import cn.hutool.core.util.StrUtil;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.mapper.CasePublicSecurityEnforcementCodeMapper;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.model.CasePublicSecurityEnforcementCode;
import com.icinfo.cloud.provider.punish.common.publicsecurityentrust.service.ICasePublicSecurityEnforcementCodeService;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author HKxxx
 * @description 针对表【case_public_security_enforcement_code(公安委托执法码信息表)】的数据库操作Service实现
 * @createDate 2024-03-11 10:35:46
 */
@Slf4j
@Service
public class CasePublicSecurityEnforcementCodeServiceImpl extends MyBatisServiceSupport
        implements ICasePublicSecurityEnforcementCodeService {

    @Resource
    private CasePublicSecurityEnforcementCodeMapper casePublicSecurityEnforcementCodeMapper;

    @Override
    public CasePublicSecurityEnforcementCode getCasePublicSecurityEnforcementCodeByOrgCode(String orgCode) {
        if (StrUtil.isBlank(orgCode)) {
            throw new BusinessException("orgCode不能为空");
        }
        // 一个机构码只有一条配置
        CasePublicSecurityEnforcementCode query = new CasePublicSecurityEnforcementCode();
        query.setOrgCode(orgCode);
        CasePublicSecurityEnforcementCode enforcementCode = casePublicSecurityEnforcementCodeMapper.selectOne(query);
        if (Objects.isNull(enforcementCode)) {
            throw new BusinessException("无相关执法编码信息");
        }
        return enforcementCode;
    }
}




